package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Companyperson;
import com.ruoyi.system.service.ICompanypersonService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 企业骨干人员和企业关联 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-04-26
 */
@Controller
@RequestMapping("/system/companyperson")
public class CompanypersonController extends BaseController
{
    private String prefix = "system/companyperson";
	
	@Autowired
	private ICompanypersonService companypersonService;
	
	@RequiresPermissions("system:companyperson:view")
	@GetMapping()
	public String companyperson()
	{
	    return prefix + "/companyperson";
	}
	
	/**
	 * 查询企业骨干人员和企业关联列表
	 */
	@RequiresPermissions("system:companyperson:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Companyperson companyperson)
	{
		startPage();
        List<Companyperson> list = companypersonService.selectCompanypersonList(companyperson);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出企业骨干人员和企业关联列表
	 */
	@RequiresPermissions("system:companyperson:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Companyperson companyperson)
    {
    	List<Companyperson> list = companypersonService.selectCompanypersonList(companyperson);
        ExcelUtil<Companyperson> util = new ExcelUtil<Companyperson>(Companyperson.class);
        return util.exportExcel(list, "companyperson");
    }
	
	/**
	 * 新增企业骨干人员和企业关联
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存企业骨干人员和企业关联
	 */
	@RequiresPermissions("system:companyperson:add")
	@Log(title = "企业骨干人员和企业关联", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Companyperson companyperson)
	{		
		return toAjax(companypersonService.insertCompanyperson(companyperson));
	}

	/**
	 * 修改企业骨干人员和企业关联
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Companyperson companyperson = companypersonService.selectCompanypersonById(id);
		mmap.put("companyperson", companyperson);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存企业骨干人员和企业关联
	 */
	@RequiresPermissions("system:companyperson:edit")
	@Log(title = "企业骨干人员和企业关联", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Companyperson companyperson)
	{		
		return toAjax(companypersonService.updateCompanyperson(companyperson));
	}
	
	/**
	 * 删除企业骨干人员和企业关联
	 */
	@RequiresPermissions("system:companyperson:remove")
	@Log(title = "企业骨干人员和企业关联", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(companypersonService.deleteCompanypersonByIds(ids));
	}
	
}
